//
//  ThirdTableViewCell.m
//  BeanTrip
//
//  Created by houlei on 15/6/30.
//  Copyright (c) 2015年 PandaGroup. All rights reserved.
//

#import "ThirdTableViewCell.h"

#define WIDTH ([UIScreen mainScreen].bounds.size.width)
#define HEIGHT ([UIScreen mainScreen].bounds.size.height)

@implementation ThirdTableViewCell

- (void)dealloc
{
    [_mySpecialOffer release];
    [_titleImageV release];
    [_titleLabel release];
    [_depart_placeLabel release];
    [_depart_datesLabel release];
    [_depart_dates release];
    [_market_priceLabel release];
    [_market_price release];
    [_min_priceLabel release];
    [_min_price release];
    [super dealloc];
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}
-(void)createSubViews
{
    //设置cell的边角
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 8.0;
    self.layer.borderWidth = 1.0;
    self.layer.borderColor = [[UIColor blackColor] CGColor];
    //设置图片
    self.titleImageV = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, WIDTH/3, WIDTH/3)];
    self.titleImageV.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.titleImageV];
    [_titleImageV release];
    //设置标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3 + 10, 5, WIDTH/3*2-10, 20)];
    self.titleLabel.text = @"环游世界之百慕大三角";
    self.titleLabel.font = [UIFont systemFontOfSize:19.0];
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    //出发日期
    self.depart_datesLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3 + 10, 35, 14*4, 20)];
    self.depart_datesLabel.text = @"出发日期";
    self.depart_datesLabel.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:self.depart_datesLabel];
    [_depart_placeLabel release];
    //用于显示网络获取的出发时间
    self.depart_dates = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3 + 76, 35, WIDTH/3*2 - 76, 20)];
    self.depart_dates.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:self.depart_dates];
    [_depart_dates release];
    //用于显示网络获取的出发地点
    self.depart_placeLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3 + 10, 55, WIDTH/3, 20)];
    self.depart_placeLabel.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:self.depart_placeLabel];
    [_depart_placeLabel release];
    //小标题特价
    self.min_priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3 + 10, WIDTH/3-20, 19*3, 20)];
    self.min_priceLabel.text = @"特价:";
    self.min_priceLabel.font = [UIFont systemFontOfSize:19.0];
    [self.contentView addSubview:self.min_priceLabel];
    [_min_priceLabel release];
    //用于显示网络获取的特价
    self.min_price = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3 + 67, WIDTH/3-20, 80, 20)];
    [self.min_price setTextColor:[UIColor redColor]];
    self.min_price.font = [UIFont systemFontOfSize:19.0];
    [self.contentView addSubview:self.min_price];
    [_min_price release];
    //小标题市场价
    self.market_priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3*2+10, WIDTH/3-20, 14*4, 20)];
    self.market_priceLabel.text = @"市场价:";
    self.market_priceLabel.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:self.market_priceLabel];
    [_market_priceLabel release];
    //用于显示网络获取的市场价
    self.market_price = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/3*2+56, WIDTH/3-20, 80, 20)];
    self.market_price.font = [UIFont systemFontOfSize:14.0];
    [self.contentView addSubview:self.market_price];
    [_market_price release];
}
//重写MySpecialOffer的set方法,用于赋值
-(void)setMySpecialOffer:(SpecialOfferModel *)mySpecialOffer
{
    if (_mySpecialOffer != mySpecialOffer) {
        [_mySpecialOffer release];
        _mySpecialOffer = [mySpecialOffer retain];
    }
    //主题图片
    NSURL *url = [NSURL URLWithString:self.mySpecialOffer.cover];
    UIImage *image = [UIImage imageNamed:@"BeanTrip"];
    [self.titleImageV sd_setImageWithURL:url placeholderImage:image];
    //设置图片边角
    self.titleImageV.layer.masksToBounds = YES;
    self.titleImageV.layer.cornerRadius = 8.0;
    self.titleImageV.layer.borderWidth = 1.0;
    self.titleImageV.layer.borderColor = [[UIColor whiteColor] CGColor];
    //标题赋值
    self.titleLabel.text = self.mySpecialOffer.title;
    //日期是数组,用stringwithformat拼接后赋值
    NSString *string = @"";
    NSMutableArray *dataArray = self.mySpecialOffer.depart_dates;
    for (int i = 0; i < dataArray.count; i++) {
        string = [NSString stringWithFormat:@"%@ %@",string,dataArray[i]];
    }
    self.depart_dates.text = string;
    //出发地赋值
    self.depart_placeLabel.text = self.mySpecialOffer.depart_place;
    //特价赋值,解析数据后,因为数据为NSNumber类型,不匹配,用description,或者使用stringWithFormat
    self.min_price.text = [self.mySpecialOffer.min_price description];//将NSNumber类型强制转化成NSString类型
    //市场价赋值
    self.market_price.text = [NSString stringWithFormat:@"%@",self.mySpecialOffer.market_price];

    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
